package com.ntschy.common.core.entity.dataobject;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ntschy.common.core.BaseEntity;
import com.ntschy.common.core.entity.enums.SysCategoryEnum;
import com.ntschy.common.core.entity.enums.SysSexEnum;
import com.ntschy.common.core.entity.enums.SysWhetherEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * user实体类
 * @author ezreal_geng
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@TableName("SYS_USER")
@ApiModel(description = "用户实体类")
public class SysUser extends BaseEntity {

    private static final long serialVersionUID = 1L;

    @TableId
    @ApiModelProperty(value = "用户ID")
    private String id;

    @TableField("RoleID")
    @ApiModelProperty(value = "角色ID")
    private String roleId;

    @TableField("RoleName")
    @ApiModelProperty(value = "角色名称")
    private String roleName;

    @TableField("DeptID")
    @ApiModelProperty(value = "部门ID")
    private String deptId;

    @TableField("DeptName")
    @ApiModelProperty(value = "部门名称")
    private String deptName;

    @TableField("CompanyID")
    @ApiModelProperty(value = "单位ID")
    private String companyId;

    @TableField("CompanyName")
    @ApiModelProperty(value = "单位名称")
    private String companyName;

    @TableField("UserName")
    @ApiModelProperty(value = "用户名")
    private String userName;

    @TableField("Category")
    @ApiModelProperty(value = "用户类别")
    private SysCategoryEnum category;

    @TableField("Mobile")
    @ApiModelProperty(value = "手机号码")
    private String mobile;

    @TableField("Sex")
    @ApiModelProperty(value = "用户性别 0=男，1=女")
    private SysSexEnum sex;

    @TableField("Password")
    @ApiModelProperty(value = "密码")
    private String password;

    @TableField("IsDisabled")
    @ApiModelProperty(value = "是否禁用")
    private SysWhetherEnum isDisabled;

    @TableField("DeviceIdentification")
    @ApiModelProperty(value = "手机设备MAC地址")
    private String deviceIdentification;

    @TableField("Remark")
    @ApiModelProperty(value = "备注")
    private String remark;

    @TableField(fill = FieldFill.INSERT, value = "CreateUserID")
    @ApiModelProperty(value = "创建人ID")
    private String createUserId;

    @TableField(fill = FieldFill.INSERT, value = "CreateTime")
    @ApiModelProperty(value = "创建时间")
    private String createTime;

    @ApiModelProperty(value = "用户角色")
    @TableField(exist = false)
    private SysRole role;

    @ApiModelProperty(value = "用户单位")
    @TableField(exist = false)
    private SysCompany company;

    @ApiModelProperty(value = "用户部门")
    @TableField(exist = false)
    private SysDept dept;

    public boolean isAdmin() {
        return isAdmin(this.id);
    }

    public static boolean isAdmin(String id) {
        return StrUtil.isNotEmpty(id) && "1".equalsIgnoreCase(id);
    }

}
